<?php

/**
 * @name 商品
 */
class Controller_Product extends \Modules\Admin\Controllers\Controller {

    /**
     * @name 商品列表
     */
    public function indexAction() {
        $obj = new \Data\Product\Product();
        $list = $obj->getList();
        $this->response['list'] = $list;
    }

    /**
     * @name 商品编辑
     */
    public function editAction() {
        $pid = intval($this->getParams('pid'));

        $params = (new \Data\Product\Product())->get($pid) ?: [];
        $this->setResponseFormat(\S\Response::FORMAT_PLAIN);
        $this->response = $this->getRenderView("", $params);
    }


    /**
     * @name 保存商品
     */
    public function saveAction() {
        $pid = intval($this->getParams('pid'));
        $price = number_format($this->getParams('price'),2);
        $minute = intval($this->getParams('minute'));

        if($pid){
            (new \Data\Product\Product())->update($price,$minute,$pid);
        }else{
            (new \Data\Product\Product())->add($price,$minute);
        }

    }

    /**
     * @name 删除商品
     */
    public function deleteAction() {
        $pid = intval($this->getParams('pid'));
        (new \Data\Product\Product())->delete($pid);

    }
}
